<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/17 0017
  Time: 上午 10:42
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>车辆信息管理--添加页</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/static/city_select/cityselect/cityLayout.css">
    <%--<link rel="stylesheet" href="/static/css/carcom.css">--%>
    <style>
        .layui-form-label {
            width: 100px;
        }
        .layui-input {
            width: 96%;
        }
        .layui-textarea{
            width: 96%;
        }
        .layui-anim {
            width: 96%;
            margin-left: 21px;
        }
    </style>
</head>
<body>
<div class="wrap_padding35">
    <form class="layui-form" action="javascript:">
        <div class="layui-form-item">
            <label class="layui-form-label">车牌号码：</label>
            <div class="layui-input-block">
                <input type="text" name="carcode" lay-verify="required|carCode" placeholder="请输入车牌号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">车辆颜色：</label>
            <div class="layui-input-block">
                <input type="text" name="carcolor" lay-verify="required" placeholder="请输入保险公司名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">购买日期：</label>
                <div class="layui-input-inline">
                    <input type="text" name="buydate" class="layui-input" id="buydate" placeholder="请选择购买日期">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">发动机号：</label>
            <div class="layui-input-block">
                <input type="text" name="enginenum" lay-verify="required" placeholder="请输入发动机号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">车架号码：</label>
            <div class="layui-input-block">
                <input type="text" name="framenum" lay-verify="required" placeholder="请输入车架号码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">车辆类型：</label>
            <div class="layui-input-block">
                <input type="text" name="cartype" lay-verify="required" placeholder="请输入车辆类型" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">车辆品牌：</label>
            <div class="layui-input-block">
                <input type="text" name="carbrand" lay-verify="required" placeholder="请输入车辆品牌" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">品牌型号：</label>
            <div class="layui-input-block">
                <input type="text" name="carbrandtype" lay-verify="required" placeholder="请输入品牌型号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="picidBtn">
                    <i class="layui-icon">&#xe67c;</i>请上传车辆图片
                </button>
                <div class="layui-upload-list">
                    <label class="layui-form-label"></label>
                    <img class="layui-upload-img" id="img" width="300px" height="300px">
                    <input type="hidden" name="picid" id="picid">
                    <p id="demoText"></p>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">自动手动：</label>
            <div class="layui-input-block">
                <select name="isauto">
                    <option value="">-- 请选择类型 --</option>
                    <option value="0">手动</option>
                    <option value="1">自动</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排量大小：</label>
            <div class="layui-input-block">
                <input type="text" name="enginesize" lay-verify="required" placeholder="请输入排量大小" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">座位数量：</label>
            <div class="layui-input-block">
                <input type="text" name="seatnum" lay-verify="required" placeholder="请输入座位数量" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">外观类型：</label>
            <div class="layui-input-block">
                <input type="text" name="facetype" lay-verify="required" placeholder="请输入外观类型" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">当前里程数字：</label>
            <div class="layui-input-block">
                <input type="text" name="totalmile" lay-verify="required|number" placeholder="请输入当前里程数字" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">下次保养里程：</label>
            <div class="layui-input-block">
                <input type="text" name="maintainmile" lay-verify="required|number" placeholder="请输入下次保养里程" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">下次保养时间：</label>
                <div class="layui-input-inline">
                    <input type="text" name="nextmaintaintime" class="layui-input" id="nextmaintaintime" placeholder="请选择下次保养时间">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">年检到期时间：</label>
                <div class="layui-input-inline">
                    <input type="text" name="yearcheckend" class="layui-input" id="yearcheckend" placeholder="请选择年检到期时间">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">保险到期时间：</label>
                <div class="layui-input-inline">
                    <input type="text" name="insuranceend" class="layui-input" id="insuranceend" placeholder="请选择保险到期时间">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">提醒手机号码：</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="required|phone" placeholder="请输入提醒手机号码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">每日租金价格：</label>
            <div class="layui-input-block">
                <input type="text" name="dayprice" lay-verify="required|number" placeholder="请输入每日租金价格" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所在区域城市：</label>

            <div class="layui-input-block">
                <input type="text" name="carcity" lay-verify="required" id="carcity" placeholder="请输入每日租金价格" autocomplete="off" class="layui-input city_input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所属租赁门店：</label>
            <div class="layui-input-block">
                <select name="deptname">
                    <option value="">-- 请选择所属租赁门店 --</option>
                    <option value="高新店">高新店</option>
                    <option value="雁塔店">雁塔店</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">车辆信息介绍：</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入车辆信息" class="layui-textarea" name="carremark"></textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="cars">立即提交</button>
                <button type="button" class="layui-btn layui-btn-primary"><a href="/cars" target="_parent">取消</a></button>
            </div>
        </div>
    </form>
</div>

<script src="/static/plugins/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script src="/static/city_select/cityselect/cityselect.js"></script>

<%--2、引入bootstrap组件--%>
<script src="/static/plugins/bootstrap/js/bootstrap.js"></script>
<%--3、bootstrap table组件以及中文包的引用--%>
<script src="/static/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="/static/plugins/bootstrap-table/bootstrap-table-zh-CN.js"></script>
<script>
    layui.use(["layer","form","element","laydate","upload"],function () {
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var upload = layui.upload;
        laydate.render({
            elem: '#buydate'
            ,type:"datetime"
        });

        laydate.render({
            elem:"#nextmaintaintime"
            ,type:"datetime"
        });

        laydate.render({
            elem:"#yearcheckend"
            ,type:"datetime"
        });

        laydate.render({
            elem:"#insuranceend"
            ,type:"datetime"
        });

        //上传图片
        var uploadInst = upload.render({
            elem: '#picidBtn'
            ,url: '/upload'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                layer.msg(res.message);
                if(res.code == 1) {
                    $("#picid").val(res.data[0]);
                }
            }
            ,error: function(){
                layer.msg("上传失败");
            }
        });

        // cityselect 插件初始化
        init_city_select($("#carcity"));  // 初始化

        form.verify({
            carCode:function (value) {                      //carCode 不是name！
                var unique = false;
                $.ajax({
                    url:'/cars/carCodeCheck',
                    data:{carcode:value},
                    dataType:'json',
                    async:false,
                    success:function(msg){
                        if (msg.code == 1){             //如果为1，表示该车牌存在
                            unique = msg.data
                        }
                    },error:function () {
                        layer.msg("服务器错误")
                    }
                });
                if (unique){
                    return "该车牌已存在！";
                }
            }
        });

        form.on('submit(cars)', function(data){
            $.ajax({
                url:"/cars/save",
                type:"post",
                data:data.field,
                dataType:"json",
                success:function (msg) {
                    if(msg.code == 1){
                        layer.msg(msg.message,{time:1000,icon:1},function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.$("#tb_cars").bootstrapTable("refresh"); // 刷新表格数据
                            parent.layer.close(index); //再执行关闭
                        })
                    } else {
                        layer.msg(msg.message,{time:3000,icon:2});
                    }
                },
                error:function () {
                    console.log("异步方法错误！")
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>
</body>
</html>
